public class Q3 {
    public static void main(String[] args) {
        int[] prime_number = new int[10000];
        int[] isprime = new int[20000];
        int number = 0;

        for(int i = 2; i < 20000; i++) {
            if (isprime[i] == 0) {
                prime_number[number] = i;
                number++;

                for (int j = i * 2; j < 20000; j+=i) {
                    isprime[j] = 1;
                }
            }
        }

        int k = 0;
        while (k < number) {
            System.out.print(prime_number[k] + " ");
            k++;
            if (k % 5 == 0)
                System.out.print("\n");
        }
    }
}